package com.zimmur.service.impl.zone;

import java.util.Date;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.zimmur.dao.zone.ITopicCommentPraiseDao;
import com.zimmur.model.zone.TopicCommentPraise;
import com.zimmur.service.zone.ITopicCommentPraiseService;
import com.zimmur.service.zone.ITopicCommentService;
import com.zimmur.tools.DateUtils;

@Service("topicCommentPraiseService")  
public class TopicCommentPraiseServiceImpl implements ITopicCommentPraiseService {
	private static Logger log=LoggerFactory.getLogger(TopicCommentPraiseServiceImpl.class);

	@Resource  
    private ITopicCommentPraiseDao topicCommentPraiseDao;
	@Resource
	private ITopicCommentService topicCommentService;

	

	@Override
	public int update(TopicCommentPraise topicCommentPraise) {
		topicCommentPraiseDao.updateByPrimaryKeySelective(topicCommentPraise);
		return 0;
	}



	@Override
	public int add(Long commentId, Long userId) {
		int i;
		TopicCommentPraise topicCommentPraise;
		topicCommentPraise=topicCommentPraiseDao.selectByCommentIdAndUserId(commentId, userId);
		if(topicCommentPraise!=null){
			i=0;
		}else{
			topicCommentPraise=new TopicCommentPraise();
			topicCommentPraise.setCommentId(commentId);
			topicCommentPraise.setUserId(userId);
			topicCommentPraise.setStatus(1);
			topicCommentPraise.setCreatedate(DateUtils.getUnixTimeByDate(DateUtils.getNow()));
			i=topicCommentPraiseDao.insertSelective(topicCommentPraise);
			
			topicCommentService.updateCommentPressNum(commentId, 1);
		}
		
		return i;
	}
}
